/*
---
name: MPG.NavigaterControl

description:

license: MIT-style

authors:
- Noritaka Horio

requires:
  - Core/Core
  - Core/Function
  - Core/Element
  - Core/Element.Event
  - Core/Class
  - Core/Class.Extras
  - Custom-Event/Element.defineCustomEvent
  - Mobile/Touch
  - Mobile/Click
  - Mobile/Browser.Features.Touch

provides: [MPG.NavigaterControl]

...
*/
(function($){

	var MPG = this.MPG = (this.MPG || {});

	MPG.NavigaterControl = new Class({

		Implements: [MPG.Control],

		options: {
			current: 0,
			total: 1,
			nextClass: 'next',
			prevClass: 'prev',
			currentClass: 'current',
			totalClass: 'total'
		},

		initialize: function(container, options){
			this.setOptions(options);
			this.container = container;
		},

		initControl: function(){
			var self = this;
			var options = this.options;
			var container = this.container;
			this._next = container.getElement('.' + options.nextClass);
			this._prev = container.getElement('.' + options.prevClass);
			this._current = container.getElement('.' + options.currentClass);
			this._total = container.getElement('.' + options.totalClass);
			this.controller.addEvent('changeEnd', this._onChange.bind(self));
			this._next.addEvent('click', this._onNext.bind(self));
			this._prev.addEvent('click', this._onPrev.bind(self));
		},

		_onChange: function(){
			var current = this.controller.getCurrent();
			var total = this.controller.getTotal();
			this._current.set('html', current + 1);
			this._total.set('html', total);
		},

		_onNext: function(){
			this.controller.next();
		},

		_onPrev: function(){
			this.controller.prev();
		}

	});

}(document.id));
